package com.tjsinfo.tjsoa.system.bo;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.tjsinfo.tjsoa.Dao.IHibernateDao;
import com.tjsinfo.tjsoa.Dao.IQbcDao;
import com.tjsinfo.tjsoa.system.dao.IChangYongYuDao;
import com.tjsinfo.tjsoa.system.vo.TSystemChangyongyu;
import com.tjsinfo.tjsoa.system.vo.TSystemChangyongyuDefault;
import com.tjsinfo.tjsoa.system.vo.TSystemChangyongyuEntry;

public class ChangYongYuBo implements IChangYongYuBo{

	private IQbcDao qbcDao;
	private IHibernateDao hibernateDao;
	public IHibernateDao getHibernateDao() {
		return hibernateDao;
	}
	public void setHibernateDao(IHibernateDao hibernateDao) {
		this.hibernateDao = hibernateDao;
	}
	private IChangYongYuDao changYongYuDao;
	public IChangYongYuDao getChangYongYuDao() {
		return changYongYuDao;
	}
	public void setChangYongYuDao(IChangYongYuDao changYongYuDao) {
		this.changYongYuDao = changYongYuDao;
	}
	public IQbcDao getQbcDao() {
		return qbcDao;
	}
	public void setQbcDao(IQbcDao qbcDao) {
		this.qbcDao = qbcDao;
	}

	public List<TSystemChangyongyu> queryAll() {
		List<TSystemChangyongyu> list = changYongYuDao.query();
		return list;
	}
	public List<TSystemChangyongyuDefault> queryChangyongyuDefaults(String id,String start,String limit) {
        DetachedCriteria criteria = DetachedCriteria.forClass(TSystemChangyongyuDefault.class);
        criteria.add(Restrictions.eq("mainId", Integer.parseInt(id)));
        qbcDao.findPageByCriteria(criteria, Integer.parseInt(limit), Integer.parseInt(start));
        List<TSystemChangyongyuDefault> list = qbcDao.getCriteria(criteria);
		return list;
	}
	public List<TSystemChangyongyuEntry> queryChangyongyuEntries(String id,
			String start, String limit) {
		DetachedCriteria criteria = DetachedCriteria.forClass(TSystemChangyongyuEntry.class);
		criteria.add(Restrictions.eq("mainId", Integer.parseInt(id)));
		qbcDao.findPageByCriteria(criteria, Integer.parseInt(limit), Integer.parseInt(start));
		List<TSystemChangyongyuEntry> list = qbcDao.getCriteria(criteria);
		return list;
	}
	public int queryTotalDefalt(String id) {
		DetachedCriteria criteria = DetachedCriteria.forClass(TSystemChangyongyuDefault.class);
		criteria.add(Restrictions.eq("mainId", Integer.parseInt(id)));
		List<TSystemChangyongyuDefault> list = qbcDao.getCriteria(criteria);
		int size = list.size();
		return size;
	}
	public int queryTotalPerson(String id) {
		DetachedCriteria criteria = DetachedCriteria.forClass(TSystemChangyongyuEntry.class);
		criteria.add(Restrictions.eq("mainId", Integer.parseInt(id)));
		List<TSystemChangyongyuEntry> list = qbcDao.getCriteria(criteria);
		int size = list.size();
		return size;
	}
	public void deleteDedalt(String id) {
        TSystemChangyongyuDefault systemChangyongyuDefault = (TSystemChangyongyuDefault)hibernateDao.findById(TSystemChangyongyuDefault.class, Integer.parseInt(id));
	    hibernateDao.delete(systemChangyongyuDefault);
	}
	public void deletePerson(String id) {
		TSystemChangyongyuEntry systemChangyongyuEntry = (TSystemChangyongyuEntry)hibernateDao.findById(TSystemChangyongyuEntry.class, Integer.parseInt(id));
		hibernateDao.delete(systemChangyongyuEntry);
		
	}
	public void updateDefalt(String id,String changyongyu) {
        TSystemChangyongyuDefault systemChangyongyuDefault = (TSystemChangyongyuDefault)hibernateDao.findById(TSystemChangyongyuDefault.class, Integer.parseInt(id));
		systemChangyongyuDefault.setSentence(changyongyu);
		hibernateDao.update(systemChangyongyuDefault);
	}
	public void updatePerson(String id,String changyongyu) {
		TSystemChangyongyuEntry systemChangyongyuEntry = (TSystemChangyongyuEntry)hibernateDao.findById(TSystemChangyongyuEntry.class, Integer.parseInt(id));
		systemChangyongyuEntry.setSentence(changyongyu);
		hibernateDao.update(systemChangyongyuEntry);
	}
	public void addDefalt(TSystemChangyongyuDefault systemChangyongyuDefault) {
		hibernateDao.save(systemChangyongyuDefault);
	}
	public void addPerson(TSystemChangyongyuEntry systemChangyongyuEntry) {
		hibernateDao.save(systemChangyongyuEntry);
	}
	public List<TSystemChangyongyuEntry> queryByUser(Integer userid,
			String start, String limit) {
		DetachedCriteria criteria = DetachedCriteria.forClass(TSystemChangyongyuEntry.class);
		criteria.add(Restrictions.eq("userId",userid));
		qbcDao.findPageByCriteria(criteria, Integer.parseInt(limit), Integer.parseInt(start));
		List<TSystemChangyongyuEntry> list = qbcDao.getCriteria(criteria);
		return list;
	}
	public String queryById(Integer id) {
		DetachedCriteria criteria = DetachedCriteria.forClass(TSystemChangyongyu.class);
		criteria.add(Restrictions.eq("nodeId", id));
		List<TSystemChangyongyu> list = qbcDao.getCriteria(criteria);
		TSystemChangyongyu changyongyu = list.get(0);
		return changyongyu.getDescription();
	}
	public List queryHuanJie() {
		DetachedCriteria criteria = DetachedCriteria.forClass(TSystemChangyongyu.class);
		List<TSystemChangyongyu> list = qbcDao.getCriteria(criteria);
		return list;
	}

	
}
